package com.lgd.design.enums;

import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;

public enum BusinessType {

    BUSINESS_01(1, "业务类型1"),
    BUSINESS_02(2, "业务类型2"),
    BUSINESS_03(3, "业务类型3");

    private final Integer code;
    private final String desc;

    BusinessType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.desc;
    }

    public static String getDescByCode(Integer code) {
        AtomicReference<BusinessType> reference = new AtomicReference<>(null);
        Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst().ifPresent(reference::set);
        return ObjectUtils.isEmpty(reference.get()) ? null : reference.get().getDesc();
    }
}
